<?php

class Silk_Mapi_Model_Quote extends Mage_Sales_Model_Quote
{
    /**
     * @param Mage_Catalog_Model_Product $product
     * @param int $qty
     * @return false|Mage_Core_Model_Abstract|Mage_Sales_Model_Quote_Item
     */
    protected function _addCatalogProduct(Mage_Catalog_Model_Product $product, $qty = 1)
    {
        $newItem = false;
        $item = $this->getItemByProduct($product);
        if (!$item) {
            $item = Mage::getModel('sales/quote_item');
            $item->setQuote($this);
            $session = Mage::getSingleton('checkout/session');
            $exchange = $session->getExchange() ? 1 : 0;
            $item->setExchange($exchange);
            $item->setActivityId($session->getActivityId());
            if (Mage::app()->getStore()->isAdmin()) {
                $item->setStoreId($this->getStore()->getId());
            } else {
                $item->setStoreId(Mage::app()->getStore()->getId());
            }

            $isGift = ($product->getId()==Mage::registry("gift_product_id"))?true:false;
            if($isGift)
            {
                $item->setOriginalCustomPrice(0);
                $item->setGiftId(Mage::registry("gift_id"));
            }

            $newItem = true;
        }

        /**
         * We can't modify existing child items
         */
        if ($item->getId() && $product->getParentProductId()) {
            return $item;
        }
        $item->setOptions($product->getCustomOptions())
            ->setProduct($product);

        // Add only item that is not in quote already (there can be other new or already saved item
        if ($newItem) {
            $this->addItem($item);
        }

        return $item;
    }
}